<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of DuoKu
 *
 * @author Samuel
 */
require_once 'BaseChannel.php';

class DuoKu implements BaseChannel {

    //put your code here
    function __construct() {
        //echo "construct";
    }

    //put your code here
    function android($data) {
        $amount = $_REQUEST['amount'];	//充值成功的金额
        $orderid = $_REQUEST['orderid'];	//订单号(如cp未提供订单号,则传入多酷订单号) 
        $result = $_REQUEST['result'];	//充值结果(1:成功, 2:失败)
        $cardtype = $_REQUEST['cardtype'];	//充值类型
        $timetamp = $_REQUEST['timetamp'];	//订单完成时的unix 时间戳 
        $aid = $_REQUEST['aid'];	//将客户端传入的 aid原样传回 
        $client_secret = $_REQUEST['client_secret'];	//sign
        $aid = urlencode($aid);	
        $appSecret = 'e55e66c423d71f139d4767f21dfe18f2';
        $sign = strtolower(md5($amount . $cardtype . $orderid . $result . $timetamp . $appSecret . $aid));
        $status = $result == 1 ? STATUS_SUCCESS : STATUS_FAILD;
        //print_r($_REQUEST);
        //var_dump($_REQUEST);
        $order = new ChargeOrder();
        $order->log("DuoKu", $_REQUEST);
        //echo " client_secret:$client_secret sign:$sign ";
        if ($client_secret == $sign) {
            $order->recordOrder($status, $amount, $orderid, "duoku", ANDROID);
        } else {
            echo 'ERROR_SIGN';
            exit;
        }
        echo "SUCCESS";
    }

    function ios($data) {
        $amount = $_REQUEST['amount'];	//充值成功的金额
        $orderid = $_REQUEST['orderid'];	//订单号(如cp未提供订单号,则传入多酷订单号) 
        $result = $_REQUEST['result'];	//充值结果(1:成功, 2:失败)
        $cardtype = $_REQUEST['cardtype'];	//充值类型
        $timetamp = $_REQUEST['timetamp'];	//订单完成时的unix 时间戳 
        $aid = $_REQUEST['aid'];	//将客户端传入的 aid原样传回 
        $client_secret = $_REQUEST['client_secret'];	//sign
        $aid = urlencode($aid);
        $AppSecret = '3691537c27c69eed29c4895b9c70c043';
        $sign = strtolower(md5($amount . $cardtype . $orderid . $result . $timetamp . $AppSecret . $aid));
        $status = $result == 1 ? STATUS_SUCCESS : STATUS_FAILD;
        
        $order = new ChargeOrder();
        $order->log("DuoKu", $_REQUEST);
        if ($client_secret == $sign) {
            $order->recordOrder($status, $amount, $orderid, "dkjk", IOS);
        } else {
            echo 'ERROR_SIGN';
            exit;
        }
        echo "SUCCESS";
    }



}
